<?php 
import("@.ORG.Page");
class ChildAction extends Action
{
   
   public function _initialize() 
   {
        
   }
   function Index()
   {
     $uid = $_REQUEST['uid'];
     $Vdao = M('Visits');
     $Udao = M('User');
 //根据uid得到孩子日志的信息
 //  用户信息
     $condition['u_id'] = $uid; 
     $Userinfo = $Udao->where($condition)->find();   
     $Userinfo['reg_date']=date('Y-m-d h:m',$Userinfo['reg_date']); 
     $Userinfo['birthday']=date('m-d-y',$Userinfo['birthday']);
//   访问信息
     $condlist['visitedid'] = $uid;
     $VisitList = $Vdao->where($condlist)->findAll();
     if(sizeof($VisitList)>6)
     {
     $start = sizeof($VisitList);
     $VisitList =$Vdao->where($condition)->order('vtime desc')->limit($start,6)->select();
     }
//   获得user的信息
     $vistors=null;
     foreach($VisitList AS $key=>$val){
        $usid = $val['visitid'];      
        $vistors[$key]=D('user')->where('u_id='.$usid)->find(); 
     }
     $scondition['uid'] = $uid;
     $ShareList = M('Share')->where($scondition)->order('ctime desc')->find();
         if($ShareList['id']>0){
           $ShareList['ctime'] = date('Y-m-d H:i:s',$ShareList['ctime']);
        }else{
           $ShareList['content'] ="该孩子还没有分享自己的每天的心情！"; 
           $ShareList['ctime'] = date('Y-m-d H:i',time()); 
        }
     $this->assign('shareList',$ShareList);
     
     $this->assign('visit',$vistors);
     $this->assign('user',$Userinfo);
     $this->assign('userid',$uid); 
     
 //获得最喜爱的东西的
     $photocond['uid'] = $uid; 
	 $Plist=M('Photos')->where($photocond)->order('id desc')->find();
     if($Plist['id']>0)
     {
       $Plist['ctime']=date('Y-m-d H:i',$Plist['ctime']);
     }
     else
     {
        $Plist['ctime']=date('Y-m-d H:i',time());
        $Plist['ph_name']="default.png";
      
     }
     $notecond['uid'] = $uid; 
     $Nlist=M('Note')->where($notecond)->order('n_id desc')->find();
     if($Nlist['n_id']>0)
     {
       $Nlist['ctime']=date('Y-m-d H:i:s',$Plist['ctime']);
     }else
     {
        $Nlist['ctime']=date('Y-m-d H:i:s',time());
        $Nlist['title']="您还没有写过博文！";
     }    
     $this->assign('plist',$Plist);
     $this->assign('nlist',$Nlist);   
     $this->display('Tpl/default/Child/publicinfo.html');
   }
   
    /**
     * 捕获孩子ID
     * @author sudi
     */
   function getChild()
   {
     $uid = $_REQUEST['uid'];
     $visitid = Session::get('uid');
     $Vdao = M('Visits');
     $Udao = M('User');
 //根据uid得到孩子日志的信息
     if($visitid==null)
     {
        echo "<div id='top_title'><div style='float:left;width:20%;'><img src='/bangbangtang/home/Tpl/default/Public/images/child/logo.png'/></div>
    <div style='float:left;width:60%;'>
      <div align='center'><img src='/bangbangtang/home/Tpl/default/Public/images/child/tell.png' style='cursor:pointer;' /></div>
    </div>   
	<div style='float:left;width:20%;height:93px; fon'><img src='/bangbangtang/home/Tpl/default/Public/images/child/login.png' style='cursor:pointer;' onclick ='toLogin()' /><img src='/bangbangtang/home/Tpl/default/Public/images/child/register.png' style='cursor:pointer;' onclick = 'toRegister()'/></div>";
     }
     if($uid!==$visitid)
     {
        $condVisit['visitedid'] = $uid;
        $condVisit['visitid'] = $visitid;
        $last = $Vdao->where($condVisit)->find();
        if($last!=null)
        {
            $data['vtime'] = time();
            $last = $Vdao->where($condVisit)->save($data);
        }
        else
        {
            $data['visitid'] = $visitid;
            $data['visitedid'] = $uid;
            $data['vtime'] = time();
            $last = $Vdao->add($data);
        }
     }
 //  用户信息
     $condition['u_id'] = $uid; 
     $Userinfo = $Udao->where($condition)->find();   
     $Userinfo['reg_date']=date('Y-m-d h:m',$Userinfo['reg_date']); 
     $Userinfo['birthday']=date('m-d-y',$Userinfo['birthday']);
//   访问信息
     $condlist['visitedid'] = $uid;
     $VisitList = $Vdao->where($condlist)->findAll();
     if(sizeof($VisitList)>6)
     {
     $start = sizeof($VisitList);
     $VisitList =$Vdao->where($condition)->order('vtime desc')->limit($start,6)->select();
     }
//   获得user的信息
     $vistors=null;
     foreach($VisitList AS $key=>$val){
        $usid = $val['visitid'];      
        $vistors[$key]=D('user')->where('u_id='.$usid)->find(); 
     }
     $scondition['uid'] = $uid;
     $ShareList = M('Share')->where($scondition)->order('ctime desc')->find();
         if($ShareList['id']>0){
           $ShareList['ctime'] = date('Y-m-d H:i',$ShareList['ctime']);
        }else{
           $ShareList['content'] ="该孩子还没有分享自己的每天的心情！"; 
           $ShareList['ctime'] = date('Y-m-d H:i:s',time()); 
        }
     $this->assign('shareList',$ShareList);
     
     $this->assign('visit',$vistors);
     $this->assign('user',$Userinfo);
     $this->assign('userid',$uid); 
     
 //获得最喜爱的东西的
     $photocond['uid'] = $uid; 
	 $Plist=M('Photos')->where($photocond)->order('id desc')->find();
     if($Plist['id']>0)
     {
       $Plist['ctime']=date('Y-m-d H:i',$Plist['ctime']);
     }
     else
     {
        $Plist['ctime']=date('Y-m-d H:i',time());
        $Plist['ph_name']="default.png";
      
     }
     $notecond['uid'] = $uid; 
     $Nlist=M('Note')->where($notecond)->order('n_id desc')->find();
     if($Nlist['n_id']>0)
     {
       $Nlist['ctime']=date('Y-m-d H:i',$Plist['ctime']);
     }else
     {
        $Nlist['ctime']=date('Y-m-d H:i:s',time());
        $Nlist['title']="您还没有写过博文！";
     }    
     $this->assign('plist',$Plist);
     $this->assign('nlist',$Nlist);   
     $this->display('Tpl/default/Child/publicchild.html');
   }
   
 /**
  * 获得相册列表
  * @author sudi
  */ 
     function getAlbum()
    {  
        $uid =$_REQUEST['userid'];
        $Form=M('Photoalbum');
        $condition['uid'] = $uid;
        $albumList = $Form->where($condition)->findAll();
  	    $this->ajaxReturn($albumList,$uid,1,'JSON');
    }
    /**
  * 获得视频列表
  * @author sudi
  */ 
     function getVideo()
    {  
        $uid =$_REQUEST['userid'];
        $condition['uid']=$uid;
        $videoslist  = M('Video')->where($condition)->findAll();
        foreach($videoslist AS $key=>$val){
          $videoslist[$key]['time']=date('Y-m-d H:i',$val['ctime']); 
          $videoslist[$key]['play_url']=U('Video/playVideo/v_id/'.$val['v_id']); 
        }  
  	    $this->ajaxReturn($videoslist,$uid,1,'JSON');
    }
 /**
  * 获得里程碑列表
  * @author sudi
  */ 
     function getFirst()
    {  
        $uid =$_REQUEST['userid'];
        $condition['uid']=$uid;
        $firstlist  = M('First')->where($condition)->findAll();
        foreach($firstlist AS $key=>$val){
          $firstlist[$key]['time']=date('Y-m-d H:i',$val['ctime']); 
          $uid = $val['uid'];
          $firstlist[$key]['p_name']=D('user')->where('u_id='.$uid)->find();  
        }  
  	    $this->ajaxReturn($firstlist,$uid,1,'JSON');
    }
    /**
  * 获得里程碑列表
  * @author sudi
  */ 
     function getFavourite()
    {  
        $uid =$_REQUEST['userid'];
        $condition['uid']=$uid;
        $firstlist  = M('Favorite')->where($condition)->findAll();
        foreach($firstlist AS $key=>$val){
          $firstlist[$key]['time']=date('Y-m-d H:i',$val['ctime']); 
          $uid = $val['uid'];
          $firstlist[$key]['p_name']=D('user')->where('u_id='.$uid)->find();  
        }  
  	    $this->ajaxReturn($firstlist,$uid,1,'JSON');
    }
   
  /**
  * 获得日志列表
  * @author sudi
  */ 
     function getNote()
    {  
        $uid =$_REQUEST['userid'];
        
        if($uid<0)
        {
          $this->error('参数错误！'); 
        }
//  获得blog的列表
        $contidion['uid']=$uid;
        $list=D('note')->where($contidion)->order('ctime desc')->findAll();
        foreach($list AS $key=>$val)
        {                  
           $list[$key]['ctime']=date('Y-m-d H:i',$val['ctime']); 
           $writeid = $val['uid'];
           $list[$key]['p_name']=D('user')->where('u_id='.$writeid)->find();                   
        } 
  	    $this->ajaxReturn($list,$uid,1,'JSON');
    }
 /**
  * 获得生长曲线
  * @author sudi
  */     
    public function getShowth()
    {
        $uid =$_REQUEST['userid'];
        $Grow = M('Growth');
        $condition['uid']=$uid;
        $List = $Grow->where($condition)->findAll();
         foreach($List AS $key=>$val){
          $List[$key]['time']=date('Y-m-d H:i',$val['time']); 
        }     
        $this->ajaxReturn($List,$uid,1,"JSON");           
    }
    
    /**
     * @author sudi
     * @2012年1月8日
     * 指向修改界面
     */
    function show_change()
    {
        $this->display('Tpl/default/Child/childinfo.html');
    } 
    /**
     * @author sudi
     * @2012年3月23日
     * 保存修改界面
     */
     
    function change_info()
    {
         $uid = Session::get('uid');
         $condition['u_id'] = $uid;
         $Udao = M('User');
         $userinfo = $Udao->where($condition)->find();
         $name = $userinfo['name'];
         $scondition['uid'] = $uid;
         $List = M('Userinfo')->where($scondition)->find();
         $this->assign('user',$userinfo);
         $this->assign('username',$name);
         $this->assign('userid',$uid); 
         $this->assign('list',$List);
         $this->display('Tpl/default/Child/childinfo.html');  
    } 
    /**
     * @author sudi
     * @2012年3月23日
     * 获取孩子信息界面
     */
     
    function getInfo()
    {
         $uid = $_POST['userid'];
         if($uid==0)                                             //文件名为空
         {
         echo"<script>alert('请确认是否登录，或者长时间离开浏览器!'); 
         window.history.back();</script>";
         }  
         $condition['uid'] = $uid;
         $List = M('Userinfo')->where($condition)->find();
        
         $this->ajaxReturn($List,$uid,1,"JSON"); 
    } 
    
   function videolist(){ 
     $uid=$_POST['userid'];
    if(empty($uid)){
       $this->error("要重新登陆哦");
       $this->redirect(U("Public/login")); 
    }
    $Vdao = M('Video');
    $condition['uid'] = $uid;
    $list  = $Vdao->where($condition)->findAll();
  
    foreach($list AS $key=>$val){
      $list[$key]['time']=date('Y-m-d H:i',$val['ctime']); 
      $list[$key]['play_url']=U('Video/playVideo/v_id/'.$val['v_id']); 
    }    
     $this->ajaxReturn($list,$uid,1,"JSON");     
  }      
     /**
     * @author sudi
     * @2012年3月23日
     * 保存修改界面
     */
     
    function saveInfo()
    {
         $uid = Session::get('uid');
         if($uid==0)                                             //文件名为空
         {
         echo"<script>alert('请确认是否登录，或者长时间离开浏览器!'); 
         window.history.back();</script>";
         }  
         $data['uid']= $uid;
         $data['nick']= $_REQUEST['nick'];
         $data['hospital'] = $_REQUEST['hospital'];
         $data['province'] = $_REQUEST['province'];
         $data['haircolor'] = $_REQUEST['haircolor'];
         $data['eyecolor'] = $_REQUEST['eyecolor'];
         $data['school'] = $_REQUEST['school'];
         $data['teacher'] = $_REQUEST['teacher'];
         $data['course'] = $_REQUEST['course'];
         $data['activity'] = $_REQUEST['activity'];
         $data['special'] = $_REQUEST['special'];
         $data['namemean'] = $_REQUEST['meaning'];
         $condition['uid'] = $uid;
         $list = M('Userinfo')->where($condition)->find();
         if($list==null)
         {
            $last = M('Userinfo')->add($data);
         }
         else{
            $last = M('Userinfo')->where($condition)->save($data);
         }
         $Public = A('Public');
         $Public->showChildTo($uid);
    }
    /**
     * @author sudi
     * @time 2012年3月12日
     */
    function addShare()
    {
        $content = $_POST['content'];
  //      $this->ajaxReturn($content,'',1,'JSON');
        $data['content'] = $content;
        $data['uid'] = Session::get('uid');
        $data['ctime'] = time();
        $dao = D('share');
        $last = $dao->add($data);
        $condition['id'] = $last;
        $List = $dao->where($condition)->find();
        
        $List['ctime'] = date('Y-m-d H:i',$List['ctime']);
        
        $this->ajaxReturn($List,'',1,'JSON');  
        
    }
    
      /**
     *从公共获得图片详情
     *@author sudi 
     */
    function toList()
    {
       $uid = $_REQUEST['uid'];
       $albumid = $_REQUEST['aid'];
       $Upload = A('Upload');
       $Upload->getPublicChild($uid,$albumid);
    }
      /**
 * @time:2012年3月3日15:21:06
 * 显示单张图片
 */
    public function fullShow()
    {
        $picID = $_REQUEST['picid'];
        $Upload = A('Upload');
        $Upload->oneShow($picID);  
    }
    
}

?>